using UnityEngine;

public class IAP : MonoBehaviour
{
	public GUISkin skin;

	private void Start()
	{
		AndroidPurchases.Load();
	}

	private void OnDestroy()
	{
		AndroidPurchases.StopInAppBilling();
	}

	private void OnGUI()
	{
		if (skin != null)
		{
			GUI.skin = skin;
		}
		BeginPage((float)Screen.width / 1.4f, (float)Screen.height / 1.1f);
		if (GUILayout.Button("Restore", GUILayout.Width(320f), GUILayout.Height(50f)))
		{
			AndroidPurchases.RestoreTransactions();
		}
		if (GUILayout.Button("Remove Ads + Support Dev", GUILayout.Width(320f), GUILayout.Height(50f)))
		{
			AndroidPurchases.PurchaseItem("spintops.full");
			foreach (PurchaseInfo purchaseInfo in AndroidPurchases.Instance.PurchaseInfos)
			{
				if (purchaseInfo.productId == "spintops.full")
				{
					PlayerPrefs.SetInt("tmp", 7);
					MonoBehaviour.print("bought");
				}
				if (purchaseInfo.productId == "android.test.purchased")
				{
					PlayerPrefs.SetInt("AttackState", 1);
					MonoBehaviour.print("bought");
				}
			}
		}
		if (GUILayout.Button("Test Purchase", GUILayout.Width(320f), GUILayout.Height(50f)))
		{
			AndroidPurchases.PurchaseItem("android.test.pucrhased");
			foreach (PurchaseInfo purchaseInfo2 in AndroidPurchases.Instance.PurchaseInfos)
			{
				if (purchaseInfo2.productId == "spintops.full")
				{
					PlayerPrefs.SetInt("tmp", 7);
					MonoBehaviour.print("bought");
				}
				if (purchaseInfo2.productId == "android.test.purchased")
				{
					PlayerPrefs.SetInt("AttackState", 1);
					MonoBehaviour.print("bought");
				}
			}
		}
		GUI.enabled = true;
		GUILayout.Label("Info:");
		GUILayout.Label(AndroidPurchases.LogInfo());
		if (GUILayout.Button("Back", GUILayout.Width(320f), GUILayout.Height(50f)))
		{
			UnityEngine.SceneManagement.SceneManager.LoadScene("mainmenu2");
		}
		EndPage();
	}

	private void PurchaseItem(string productID)
	{
		UnityEngine.Debug.Log("ANDROID - PurchaseItem");
		AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.platoevolved.inappbilling.UnityAndroidInterface");
		androidJavaClass.CallStatic("PurchaseItem", productID);
	}

	private void BeginPage(float width, float height)
	{
		GUILayout.BeginArea(new Rect(((float)Screen.width - width) / 2f, ((float)Screen.height - height) / 2f, width, height));
	}

	private void EndPage()
	{
		GUILayout.EndArea();
	}
}
